forked from
quillmatiq.com/augment
Fork of Chiri for Astro for my blog
1import { getCollection, type CollectionEntry } from 'astro:content'
2import { OGImageRoute } from 'astro-og-canvas'
3import { themeConfig } from '../../config'
4
5export const prerender = true
6
7const collectionEntries = await getCollection('posts')
8
9// Map the array of content collection entries to create an object.
10// Converts [{ id: 'post.md', data: { title: 'Example', pubDate: Date } }]
11// to { 'post.md': { title: 'Example', pubDate: Date } }
12const pages = Object.fromEntries(
13 collectionEntries.map((entry: CollectionEntry<'posts'>) => [entry.id.replace(/\.(md|mdx)$/, ''), entry.data])
14)
15
16export const { getStaticPaths, GET } = await OGImageRoute({
17 param: 'route',
18 pages,
19 getImageOptions: (_path: string, page: CollectionEntry<'posts'>['data']) => ({
20 title: page.title,
21 description: themeConfig.site.title,
22 logo: {
23 path: 'public/og/og-logo.png',
24 size: [80, 80]
25 },
26 bgGradient: [[255, 255, 255]],
27 bgImage: {
28 path: 'public/og/og-bg.png',
29 fit: 'fill'
30 },
31 padding: 64,
32 font: {
33 title: {
34 color: [28, 28, 28],
35 size: 68,
36 weight: 'SemiBold',
37 families: ['PingFang SC']
38 },
39 description: {
40 color: [180, 180, 180],
41 size: 40,
42 weight: 'Medium',
43 families: ['PingFang SC']
44 }
45 },
46 fonts: [
47 'https://cdn.jsdelivr.net/npm/font-pingfang-sc-font-weight-improved@latest/PingFangSC-Medium.woff2',
48 'https://cdn.jsdelivr.net/npm/font-pingfang-sc-font-weight-improved@latest/PingFangSC-Semibold.woff2'
49 ]
50 })
51})